#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
//#include <stdlib.h>

int main(int argc, char **argv)
{
	char str[100] = {0};

	int fd = open("test.txt", O_WRONLY | O_CREAT | O_RDONLY, 0777);
	if(fd < 0)
	{
		perror("open error");
		return -1;
	}
	if(write(fd, "hello world!", sizeof("hello world!")) < 0)
	{
		perror("write error");
		return -1;
	}
	close(fd);
	fd = open("test.txt", O_RDONLY);
	if(read(fd, str, sizeof(str)) < 0)
	{
		perror("read error");
		return -1;
	}
	printf("%s\n", str);
	close(fd);
	return 0;
}
